/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  @endpointMap = {
    cn-hangzhou = 'saf.cn-shanghai.aliyuncs.com',
  };

  checkConfig(config);
  @endpoint = getEndpoint('saf', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model ExecuteExtendServiceRequest {
  region?: string(name='Region'),
  service?: string(name='Service'),
  serviceParameters?: string(name='ServiceParameters'),
}

model ExecuteExtendServiceResponseBody = {
  code?: string(name='Code'),
  data?: {
    invokeResult?: string(name='InvokeResult'),
  }(name='Data'),
  httpStatusCode?: string(name='HttpStatusCode'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model ExecuteExtendServiceResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ExecuteExtendServiceResponseBody(name='body'),
}

async function executeExtendServiceWithOptions(request: ExecuteExtendServiceRequest, runtime: Util.RuntimeOptions): ExecuteExtendServiceResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.region)) {
    query['Region'] = request.region;
  }
  if (!Util.isUnset(request.service)) {
    query['Service'] = request.service;
  }
  if (!Util.isUnset(request.serviceParameters)) {
    query['ServiceParameters'] = request.serviceParameters;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ExecuteExtendService',
    version = '2019-05-21',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function executeExtendService(request: ExecuteExtendServiceRequest): ExecuteExtendServiceResponse {
  var runtime = new Util.RuntimeOptions{};
  return executeExtendServiceWithOptions(request, runtime);
}

model ExecuteRequestRequest {
  service?: string(name='Service'),
  serviceParameters?: string(name='ServiceParameters'),
}

model ExecuteRequestResponseBody = {
  code?: int32(name='Code'),
  data?: map[string]any(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
}

model ExecuteRequestResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ExecuteRequestResponseBody(name='body'),
}

async function executeRequestWithOptions(request: ExecuteRequestRequest, runtime: Util.RuntimeOptions): ExecuteRequestResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.service)) {
    query['Service'] = request.service;
  }
  if (!Util.isUnset(request.serviceParameters)) {
    query['ServiceParameters'] = request.serviceParameters;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ExecuteRequest',
    version = '2019-05-21',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function executeRequest(request: ExecuteRequestRequest): ExecuteRequestResponse {
  var runtime = new Util.RuntimeOptions{};
  return executeRequestWithOptions(request, runtime);
}

model ExecuteRequestMLRequest {
  lang?: string(name='Lang'),
  service?: string(name='Service'),
  serviceParameters?: string(name='ServiceParameters'),
}

model ExecuteRequestMLResponseBody = {
  code?: int32(name='Code'),
  data?: map[string]any(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
}

model ExecuteRequestMLResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ExecuteRequestMLResponseBody(name='body'),
}

async function executeRequestMLWithOptions(request: ExecuteRequestMLRequest, runtime: Util.RuntimeOptions): ExecuteRequestMLResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.lang)) {
    query['Lang'] = request.lang;
  }
  if (!Util.isUnset(request.service)) {
    query['Service'] = request.service;
  }
  if (!Util.isUnset(request.serviceParameters)) {
    query['ServiceParameters'] = request.serviceParameters;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ExecuteRequestML',
    version = '2019-05-21',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function executeRequestML(request: ExecuteRequestMLRequest): ExecuteRequestMLResponse {
  var runtime = new Util.RuntimeOptions{};
  return executeRequestMLWithOptions(request, runtime);
}

model ExecuteRequestSGRequest {
  lang?: string(name='Lang'),
  service?: string(name='Service'),
  serviceParameters?: string(name='ServiceParameters'),
}

model ExecuteRequestSGResponseBody = {
  code?: int32(name='Code'),
  data?: map[string]any(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
}

model ExecuteRequestSGResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ExecuteRequestSGResponseBody(name='body'),
}

async function executeRequestSGWithOptions(request: ExecuteRequestSGRequest, runtime: Util.RuntimeOptions): ExecuteRequestSGResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.lang)) {
    query['Lang'] = request.lang;
  }
  if (!Util.isUnset(request.service)) {
    query['Service'] = request.service;
  }
  if (!Util.isUnset(request.serviceParameters)) {
    query['ServiceParameters'] = request.serviceParameters;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ExecuteRequestSG',
    version = '2019-05-21',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function executeRequestSG(request: ExecuteRequestSGRequest): ExecuteRequestSGResponse {
  var runtime = new Util.RuntimeOptions{};
  return executeRequestSGWithOptions(request, runtime);
}

model GetTokenResponseBody = {
  code?: int32(name='Code'),
  data?: map[string]any(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
}

model GetTokenResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetTokenResponseBody(name='body'),
}

async function getTokenWithOptions(runtime: Util.RuntimeOptions): GetTokenResponse {
  var req = new OpenApi.OpenApiRequest{};
  var params = new OpenApi.Params{
    action = 'GetToken',
    version = '2019-05-21',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getToken(): GetTokenResponse {
  var runtime = new Util.RuntimeOptions{};
  return getTokenWithOptions(runtime);
}

model RequestDecisionRequest {
  eventCode?: string(name='EventCode'),
  serviceParameters?: string(name='ServiceParameters'),
}

model RequestDecisionResponseBody = {
  code?: long(name='Code'),
  data?: map[string]any(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
}

model RequestDecisionResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: RequestDecisionResponseBody(name='body'),
}

async function requestDecisionWithOptions(request: RequestDecisionRequest, runtime: Util.RuntimeOptions): RequestDecisionResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.eventCode)) {
    query['EventCode'] = request.eventCode;
  }
  if (!Util.isUnset(request.serviceParameters)) {
    query['ServiceParameters'] = request.serviceParameters;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'RequestDecision',
    version = '2019-05-21',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function requestDecision(request: RequestDecisionRequest): RequestDecisionResponse {
  var runtime = new Util.RuntimeOptions{};
  return requestDecisionWithOptions(request, runtime);
}

